package cn.jt.controller;


import cn.jt.pojo.ItemCat;
import cn.jt.service.ItemCatService;
import cn.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/itemCat")
public class ItemCatController {
    @Autowired
    ItemCatService itemCatService;
    @GetMapping("/findItemCatList/{level}")
    public SysResult getItem(@PathVariable Integer level){
        return  SysResult.success(itemCatService.itemCatService(level));
    }


    @PutMapping("/status/{id}/{status}/{level}")
    public SysResult updateStatus(@PathVariable Integer id,
                                  @PathVariable boolean status,
                                  @PathVariable Integer level){
        ItemCat itemCat=new ItemCat();
        itemCat.setId(id).setStatus(status).setLevel(level);
        itemCatService.updateStatus(itemCat);
        System.out.println(itemCat.getLevel());
        return  SysResult.success();
    }

    @PutMapping("/updateItemCat")
    public SysResult updateItemCat(@RequestBody ItemCat itemCat){
        itemCatService.updateItemCat(itemCat);
        return  SysResult.success();
    }

    @PostMapping("/saveItemCat")
    public SysResult saveItemCat(@RequestBody ItemCat itemCat){
        itemCatService.saveItemCat(itemCat);
        return  SysResult.success();
    }

    @DeleteMapping("/deleteItemCat")
    public SysResult deleteItemCat( ItemCat itemCat) {
        itemCatService.deleteItemCat(itemCat);
        return SysResult.success();
    }
}
